Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aprs: adding working supply #453

Merged
merged 26 commits into from
Sep 25, 2023
Merged

aprs: adding working supply #453

merged 26 commits into from
Sep 25, 2023

Conversation

gmbronco
Copy link
Contributor

Adding working supply to the BAL APR calculations. There are still differences on mainnet after checking with the current SDK APRs.

Copy link
Contributor

@franzns franzns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall good, thanks. A few comments in the code, main two issues:

  1. working supply doesnt exist on v1 gauges
  2. bal inflation rate could be queried from the tokenAdmin contract?

const results = (await multicall.execute()) as {
[address: string]: {
inflationRate: BigNumber | undefined,
workingSupply: BigNumber
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v1 gauges don't have a workingSupply

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, it will be used only in V2 and mainnet.

* @param gaugeAddresses
* @returns
*/
private async getMainnetGaugeRates(gaugeAddresses: string[]): Promise<{ [gaugeAddress: string]: GaugeRate }> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there also v1 and v2 mainnet gauges that need separate handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it's too much branching. i refactored it, but it's still quite hard to read.

Comment on lines 242 to 246
const abi = [
'function working_supply() view returns (uint256)',
'function gauge_relative_weight(address) view returns (uint256)'
];
const multicall = new Multicaller3(abi);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the gaugeController ABI is present under modules/vebal/abi . I'd suggest to move to modules/web3/abi and import from there. If we do this inline like this, I'm sure at some point the gaugeController changes and these functions are different

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to the ABI, we might need to do some work anyways when it changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this import seems to be breaking in the github workflow, would you know why?


const weightedRates = _.mapValues(gaugeData, ({ weight }) => {
if (weight.eq(0)) return 0;
return inflationRate * Number(formatUnits(weight));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually to parseFloat(), is there a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no difference, changed to parseFloat

});

const gaugeData = await multicall.execute() as { [address: string]: { weight: BigNumber, workingSupply: BigNumber } };
const inflationRate = emissions.weekly(now) / 604800; // BAL inflation rate per second
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just use

/**
     * @notice Returns the current inflation rate of BAL per second
     */
    function getInflationRate() external view returns (uint256) {
        return _rate;
    }

from the tokenAdmin contract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes we could. should I add it this call? it's returning exactly the same data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that would be great if you could add it. I like to have an onchain query rather than local calculation, saves a lot of code and less room for error

@@ -470,6 +470,7 @@ model PrismaPoolStakingGauge {
rewards PrismaPoolStakingGaugeReward[]
status PrismaPoolStakingGaugeStatus @default(ACTIVE)
version Int @default(1)
workingSupply String @default("0.0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be added to pool.prisma in the pool module

@@ -1,221 +1,252 @@
/**
* Supports calculation of BAL rewards sent to gauges. Balancer setup has 3 types of gauges:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also supports any thirdparty reward tokens

@@ -92,12 +92,22 @@ export class GaugeAprService implements PoolAprService {
const aprItemId = `${pool.id}-${rewardTokenDefinition.symbol}-apr`;
const aprRangeId = `${pool.id}-bal-apr-range`;

// Only 40% of LP token staked accrue emissions, totalSupply = workingSupply * 2.5
const workingSupply = (parseFloat(preferredStaking.gauge.workingSupply) + 0.4) / 0.4;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already get the working supply, why +0.4)/0.4 ?

@gmbronco gmbronco marked this pull request as ready for review September 20, 2023 14:49
@gmbronco gmbronco merged commit 408f2c7 into v3-canary Sep 25, 2023
1 check passed
@gmbronco gmbronco deleted the aprs-fixes branch September 25, 2023 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants